package com.sky.controller.user;

import com.sky.entity.Dish;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * PROJECT_NAME: sky-take-out
 * NAME: DishController
 * USER: zhang
 * DATE: 2023/5/21
 * DESCRIPTION :
 */
@Slf4j
@RestController("userDishController")
@Api(tags = "C端-菜品信息表现层接口")
@RequestMapping("/user/dish")
public class DishController {
    @Resource
    private DishService dishService;

    /**
     * 查询指定分类菜品和口味
     *
     * @param categoryId 菜品类别id
     * @return 全局返回信息Bean(包含菜品基本信息+口味信息)
     */
    @GetMapping("/list")
    //自动通过固定前缀DISH_CACHE,通过::,拼接categoryId(DISH_CACHE::categoryId作为key查询有没有值,有就不执行下面的方法
    // 没有，就执行下面方法，并把方法返回值放到redis中)
    @Cacheable(cacheNames = "DISH_CACHE",key = "#categoryId")
    public Result<List<DishVO>> selectDishAndFlavorByCategoryId(Long categoryId){

        return Result.success(dishService.selectDishAndFlavorByCategoryId(categoryId));
    }

}
